/**
 * 
 */
package org.leo.tree.main;

import java.util.ArrayList;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.leo.tree.beans.Output;
import org.leo.tree.beans.Tree;
import org.leo.tree.handler.LocationFetcher;
import org.leo.tree.handler.TreeXMLHandler;

/**
 * @author brij
 * 
 */
public class ParseTreeXML {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try {

			SAXParserFactory factory = SAXParserFactory.newInstance();
			SAXParser saxParser = factory.newSAXParser();
			TreeXMLHandler treeXMLHandler = new TreeXMLHandler();

			saxParser.parse("/mnt/hgfs/Documents/programs/xml_street_trees/StreetTrees_Strathcona.xml", 
							treeXMLHandler);
			ArrayList<Tree> trees = treeXMLHandler.getListOfTrees();
			System.out.println("Num of trees : " + trees.size());
			LocationFetcher locationFetcher = new LocationFetcher();
			for (Tree tree : trees) {
				String address = tree.getCivicNumber() + " " + tree.getStdStreet() + " Canada";
				System.out.println("Tree address : " + address);
				Output output = locationFetcher.getLocationOutput(address);
				System.out.println("Output : " + output.getLat() + "   " + output.getLng());
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}
